package top.huiwow.serverkick;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class ServerKickCommand implements CommandExecutor {


    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (args.length <1){
            sender.sendMessage("Wrong usage!Correct usage:/kick [player] [reason]");
        }else {
            if (args.length == 1) {
                Player player;
                player = Bukkit.getPlayer(args[0]);
                if (player == null) {
                    sender.sendMessage("Cannot find the player!");
                } else {
                    player.kickPlayer("You have been kicked from the server.");
                }
            }else {
                Player player;
                player = Bukkit.getPlayer(args[0]);
                if (player == null) {
                    sender.sendMessage("Cannot find the player!");
                } else {
                    StringBuilder reason=new StringBuilder();
                    for (int i=1;i<args.length;i++){
                        reason.append(args[i]);
                        reason.append(" ");
                    }
                    player.kickPlayer(reason.toString());
                }
            }
        }
        return true;
    }
}
